<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Gym Rat | View Log</title>
<style type="text/css">
@import "${pageContext.request.contextPath}/js/jquery.datepick.css";
</style>
<script type="text/javascript"
	src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.datepick.js"></script>
<script type="text/javascript">

$(function() {
	$('#startDatePicker').datepick();
	$('#endDatePicker').datepick();
});

function dateFilter(){
if ($('#dateCheck').is(':checked')){
		$('#startDatePicker').datepick('enable');
		$('#endDatePicker').datepick('enable');
		$('#startDatePicker').removeAttr('disabled');
		$('#endDatePicker').removeAttr('disabled');
	} else {
		$('#startDatePicker').attr('disabled','disabled');
		$('#endDatePicker').attr('disabled','disabled');
	}
}

function routineFilter(){
if ($('#routineCheck').is(':checked')){
	$('#routineSelect').removeAttr('disabled');
	} else {
	$('#routineSelect').attr('disabled','disabled');
	}
}

function exerciseFilter(){
if ($('#exerciseCheck').is(':checked')){
	$('#exerciseSelect').removeAttr('disabled');
	} else {
	$('#exerciseSelect').attr('disabled','disabled');
	}
}
</script>
</head>
<body>
<jsp:include page="/includes/nav.jsp" />
<h1>Workout Log</h1>
<ul>
	<li>View your entire workout history, sorted by date then routine.</li>
	<li><i>Filter by date range, <del>routine, exercise.</del></i></li>
</ul>
<form id="form1"
	action="${pageContext.request.contextPath}/log/view/filter"
	method="get">
<fieldset>
<table width="100%">
	<tr>
		<td class="checkBoxOptionTd"><input type="checkbox" name="filter"
			id="dateCheck" value="byDate"
			<c:if test="${dateFilter == true }">
		checked="yes"
		</c:if>
			onClick="dateFilter()"><label for="dateCheck">Filter
		by Date</label></td>
		<td class="checkBoxOptionTd"><input type="checkbox" name="filter"
			id="routineCheck" value="byRoutine" onClick="routineFilter()"
			<c:if test="${routineFilter == true }">
		checked="yes"
		</c:if>><label
			for="routineCheck">Filter by Routine:</label></td>
		<td class="checkBoxOptionTd"><input type="checkbox" name="filter"
			value="byExercise" id="exerciseCheck" onClick="exerciseFilter()"
			<c:if test="${exerciseFilter == true }">
		checked="yes"
		</c:if>><label
			for="exerciseCheck"> Filter by Exercise</label></td>
	</tr>
	<tr>
		<td>Start Date: <input type="text" name="startDate"
			id="startDatePicker" value="${startDate }" 
			<c:if test="${dateFilter != true }">
		disabled="disabled"
		</c:if>></td>
		<td>Select Routine: <select id="routineSelect"
			name="routineSelect"
			<c:if test="${routineFilter != true }">
				disabled="disabled"
				</c:if>>

			<option value="0">-none-</option>
			<c:forEach var="routine" items="${routines }">
				<option value="${routine.id }"
					<c:if
					test="${routine.id == routineChoice }">
		selected="selected"
		</c:if>>
				${routine.name }</option>
			</c:forEach>
		</select></td>
		<td>Select Exercise: <select id="exerciseSelect"
			name="exerciseSelect" 
			<c:if test = "${exerciseFilter != true }">
					disabled="disabled"
					</c:if>>
			<c:forEach var="exercise" items="${exercises }">
				<option value="${exercise.id }"
					<c:if
					test="${exercise.id == exerciseChoice }">
		selected="selected"
		</c:if>>${exercise.name}</option>
			</c:forEach>
		</select></td>
	</tr>
	<tr>
		<td>End Date: <input type="text" name="endDate"
			id="endDatePicker" value="${endDate }"
			<c:if test="${dateFilter != true }">
		disabled="disabled"
		</c:if>></td>
		<td></td>

	</tr>
	<tr>
		<td><input type="submit" value="Filter"></td>
	</tr>
</table>
</fieldset>
</form>
<table width="100%">
	<tr class="tableHeader">
		<td>Date:</td>
		<td>Routine:</td>
		<td>Exercise:</td>
		<td>Variation:</td>
		<td>Equipment</td>
		<td>Reps:</td>
		<td>Weight:</td>
		<td></td>
	</tr>
	<c:forEach var="entry" items="${log}">
		<tr class="tableSubHeader">
			<td><fmt:formatDate pattern='E, MM/dd/yyyy'
				value='${entry.dateWorked}' /></td>
			<td>${entry.routineName } <c:if
				test="${entry.routineName == null }">
				<i>Deleted Routine</i>
			</c:if></td>
			<td>${entry.exerciseName }</td>
			<td>${entry.variationName }</td>
			<td>${entry.equipmentName }</td>
			<td></td>
			<td></td>
			<td><a class="headerLink"
				href="<c:url value='/log/show?id=${entry.id}' />">edit</a></td>
		</tr>
		<c:forEach var="set" items="${entry.sets}" varStatus="status">
			<c:choose>
				<c:when test="${status.count % 2 == 1 }">
					<c:set var="rowClass" value="tableOddRow" />
				</c:when>
				<c:otherwise>
					<c:set var="rowClass" value="tableEvenRow" />
				</c:otherwise>
			</c:choose>
			<tr class="${rowClass }">
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>${set.reps }</td>
				<td>${set.weight }</td>
				<td></td>
			</tr>
		</c:forEach>
	</c:forEach>
</table>
</body>
</html>